<?php
IncludeFunction("tourtype");
IncludeFunction("location");

function ListTour($idP=0,$status=-1,$loc=-1,$search='')
{
    global $dbsql,$language;

    $sql_where  = "from tblsettour where cLanguage='$language' ";
    if($idP>0)
    {
        $sql_where.= " and iParentId = $idP ";
    }
    if($status>-1)
    {
        $sql_where.= " and iStatus   = $status ";
    }
    if($loc>-1)
    {
        $sql_where.= " and iLocationId   = $loc ";
    }
    if(!empty($search))
    {
        $sql_where.= " and cName like '$search%' ";
    }
    //----------split page
    $sql_select = "select count(iId) as count ".$sql_where;
    $result     = $dbsql->query_fetch($sql_select);
    $count_all  = $result['count'];
    list($limit_st,$limit_le)=Slit_Page($count_all);

    //--------------------------------------------------
    $sql_select = "select * ".$sql_where." order by iOrder limit $limit_st,$limit_le";
    return $dbsql->load($sql_select);

}

function LoadTourById($id)
{
    global $dbsql,$language;

    $sql_select = "select * from tblsettour where iId=$id";
    return $dbsql->query_fetch($sql_select);
}
//tour element:

function ListTourElement($idP)
{
    global $dbsql,$language;
    $idP    = intval($idP);
    $sql_select="select * from tblsettourelm where iParentId = $idP order by iOrder ";
    return $dbsql->load($sql_select);
}

function ListTabsByTour($id)
{
    global $dbsql,$language;

    $sql_select = "select * from tbltourtab where iParentId=$id order by iOrder";
    return $dbsql->load($sql_select);
}

function DelTour($id)
{
global $dbsql,$language;

    $id         = intval($id);
    $sql_delete = "DELETE FROM tblsettour WHERE iId ='$id'";
    return $dbsql->query($sql_delete);
}
function DelTourElmByTourId($idP)
{
    global $dbsql,$language;

    $idP        = intval($idP);
    $sql_delete = "DELETE FROM tblsettourelm where iParentId=$idP";
    return $dbsql->query($sql_delete);
}

function DelTourTabByTourId($idP)
{
    global $dbsql,$language;

    $idP        = intval($idP);
    $sql_select = "SELECT * FROM tbltourtab WHERE iParentId = $idP";
    $result     = $dbsql->query_fetch($sql_select);
    $id         = intval($result['iId']);
    if($result['cType']=="Image")
    {
        $sql_delete = "delete from tblgallery where iParentId=$id and cType='tourtab' ";
        $dbsql->query($sql_delete);
    }
    $sql_delete = "DELETE FROM tbltourtab WHERE iId = $id";
    return $dbsql->query($sql_delete);
}

function ListPhotoTour($id)
{
    global $dbsql,$language;
    
    $id         = intval($id);
    $sql_select = "select * from tblgallery where cType='tour' and iParentId=$id order by iOrder";
    return $dbsql->load($sql_select);
}
?>